home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / lib / saveargs.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-07  |  2.5 KB  |  120 lines

  1. /* @(#)saveargs.c    1.9 00/05/07 Copyright 1995 J. Schilling */
  2. /* save argc, argv for command error printing routines */
  3. /*
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2, or (at your option)
  7.  * any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; see the file COPYING.  If not, write to
  16.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  */
  18.  
  19. #include <mconfig.h>
  20. #include <standard.h>
  21. #include <strdefs.h>
  22. #include <stdxlib.h>
  23. #include <avoffset.h>
  24. #include <schily.h>
  25.  
  26. #if    !defined(AV_OFFSET) || !defined(FP_INDIR)
  27. #    ifdef    HAVE_SCANSTACK
  28. #    undef    HAVE_SCANSTACK
  29. #    endif
  30. #endif
  31. #ifdef    NO_SCANSTACK
  32. #    ifdef    HAVE_SCANSTACK
  33. #    undef    HAVE_SCANSTACK
  34. #    endif
  35. #endif
  36.  
  37. static    int    ac_saved;
  38. static    char    **av_saved;
  39. static    char    *av0_saved;
  40. static    char    *progname_saved;
  41.  
  42. static    char    av0_sp[32];    /* av0 space, avoid malloc() in most cases */
  43. static    char    prn_sp[32];    /* name space, avoid malloc() in most cases */
  44. static    char    dfl_str[] = "?";
  45.  
  46. void save_args(ac, av)
  47.     int    ac;
  48.     char    *av[];
  49. {
  50.     int    slen;
  51.  
  52.     ac_saved = ac;
  53.     av_saved = av;
  54.  
  55.     if (av0_saved && av0_saved != av0_sp)
  56.         free(av0_saved);
  57.  
  58.     slen = strlen(av[0]) + 1;
  59.  
  60.     if (slen <= (int)sizeof(av0_sp))
  61.         av0_saved = av0_sp;
  62.     else
  63.         av0_saved = malloc(slen);
  64.  
  65.     if (av0_saved)
  66.         strcpy(av0_saved, av[0]);
  67. }
  68.  
  69. int saved_ac()
  70. {
  71.     return (ac_saved);
  72. }
  73.  
  74. char **saved_av()
  75. {
  76.     return (av_saved);
  77. }
  78.  
  79. char *saved_av0()
  80. {
  81.     return (av0_saved);
  82. }
  83.  
  84. void set_progname(name)
  85.     const char    *name;
  86. {
  87.     int    slen;
  88.  
  89.     if (progname_saved && progname_saved != prn_sp)
  90.         free(progname_saved);
  91.  
  92.     slen = strlen(name) + 1;
  93.  
  94.     if (slen <= sizeof(prn_sp))
  95.         progname_saved = prn_sp;
  96.     else
  97.         progname_saved = malloc(slen);
  98.  
  99.     if (progname_saved)
  100.         strcpy(progname_saved, name);
  101. }
  102.  
  103. char *get_progname()
  104. {
  105. #ifdef    HAVE_SCANSTACK
  106.     char    *progname;
  107. #endif
  108.  
  109.     if (progname_saved)
  110.         return (progname_saved);
  111.     if (av0_saved)
  112.         return (av0_saved);
  113. #ifdef    HAVE_SCANSTACK
  114.     progname = getav0();        /* scan stack to get argv[0] */
  115.     if (progname)
  116.         return (progname);
  117. #endif
  118.     return (dfl_str);
  119. }
  120.